package com.app.controller;


import com.app.common.FinancingTool;
import com.app.common.NatureTool;
import com.app.common.ScaleTool;
import com.app.mapper.akesai.*;
import com.app.mapper.dunhuang.*;
import com.app.mapper.guazhou.*;
import com.app.mapper.jinta.*;
import com.app.mapper.subei.*;
import com.app.mapper.suzhou.*;
import com.app.mapper.yumen.*;
import com.app.model.*;
import com.app.service.*;
import com.app.util.Result;
import com.app.util.StringTool;
import com.app.util.TokenUtils;
import com.app.vo.DataVo;
import com.app.vo.EnterpriseVo;
import com.app.vo.ScaleVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Maps;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Controller
public class CompanyController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private ComRecruitersSuzhouMapper comRecruitersSuzhouMapper;
    @Autowired
    private JobPublishSuzhouMapper jobPublishSuzhouMapper;
    @Autowired
    private WorkApplySuzhouMapper workApplySuzhouMapper;
    @Autowired
    private EnterpriseAlbumSuzhouMapper enterpriseAlbumSuzhouMapper;
    @Autowired
    private ComRecruitersJintaMapper comRecruitersJintaMapper;
    @Autowired
    private JobPublishJintaMapper jobPublishJintaMapper;
    @Autowired
    private WorkApplyJintaMapper workApplyJintaMapper;
    @Autowired
    private EnterpriseAlbumJintaMapper enterpriseAlbumJintaMapper;
    @Autowired
    private ComRecruitersDunhuangMapper comRecruitersDunhuangMapper;
    @Autowired
    private JobPublishDunhuangMapper jobPublishDunhuangMapper;
    @Autowired
    private WorkApplyDunhuangMapper workApplyDunhuangMapper;
    @Autowired
    private EnterpriseAlbumDunhuangMapper enterpriseAlbumDunhuangMapper;
    @Autowired
    private ComRecruitersGuazhouMapper comRecruitersGuazhouMapper;
    @Autowired
    private JobPublishGuazhouMapper jobPublishGuazhouMapper;
    @Autowired
    private WorkApplyGuazhouMapper workApplyGuazhouMapper;
    @Autowired
    private EnterpriseAlbumGuazhouMapper enterpriseAlbumGuazhouMapper;
    @Autowired
    private ComRecruitersYumenMapper comRecruitersYumenMapper;
    @Autowired
    private JobPublishYumenMapper jobPublishYumenMapper;
    @Autowired
    private WorkApplyYumenMapper workApplyYumenMapper;
    @Autowired
    private EnterpriseAlbumYumenMapper enterpriseAlbumYumenMapper;
    @Autowired
    private ComRecruitersSubeiMapper comRecruitersSubeiMapper;
    @Autowired
    private JobPublishSubeiMapper jobPublishSubeiMapper;
    @Autowired
    private WorkApplySubeiMapper workApplySubeiMapper;
    @Autowired
    private EnterpriseAlbumSubeiMapper enterpriseAlbumSubeiMapper;
    @Autowired
    private ComRecruitersAkesaiMapper comRecruitersAkesaiMapper;
    @Autowired
    private JobPublishAkesaiMapper jobPublishAkesaiMapper;
    @Autowired
    private WorkApplyAkesaiMapper workApplyAkesaiMapper;
    @Autowired
    private EnterpriseAlbumAkesaiMapper enterpriseAlbumAkesaiMapper;
    @Autowired
    private EnterpriseSuzhouMapper enterpriseSuzhouMapper;
    @Autowired
    private EnterpriseJintaMapper enterpriseJintaMapper;
    @Autowired
    private EnterpriseDunhuangMapper enterpriseDunhuangMapper;
    @Autowired
    private EnterpriseGuazhouMapper enterpriseGuazhouMapper;
    @Autowired
    private EnterpriseYumenMapper enterpriseYumenMapper;
    @Autowired
    private EnterpriseSubeiMapper enterpriseSubeiMapper;
    @Autowired
    private EnterpriseAkesaiMapper enterpriseAkesaiMapper;
    @Autowired
    private IndustryMapper industryMapper;
    @Autowired
    private StatisticsService statisticsService;

    /**
     * 企业列表
     *
     * @param page
     * @param limit
     * @param keyWord
     * @param scaleId
     * @param addressId
     * @param request
     * @return
     */
    @GetMapping("/getCompanyList")
    public Result<Object> getCompanyList(
            int page, int limit,
            @RequestParam(required = false) String keyWord,
            @RequestParam(required = false) Integer scaleId,
            @RequestParam(required = false) Integer addressId,
            HttpServletRequest request) {
        String token = request.getHeader("token");
        String userId = TokenUtils.nothingness(token);
        if (userId == null) {
            return Result.error(405, "token不存在");
        }
        AdminUserModel user = adminUserService.getUserById(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        EnterpriseVo vo = new EnterpriseVo();
        EnterpriseModel model = new EnterpriseModel();
        model.setKeyWord(keyWord);
        model.setScaleId(scaleId);
        model.setPage((page - 1) * limit);
        model.setLimit(limit);
        if (addressId != null && addressId != 0) {
            if (addressId == 1) {
                return Result.success(suzhouCompanyList(model));
            } else if (addressId == 2) {
                return Result.success(jintaCompanyList(model));
            } else if (addressId == 3) {
                return Result.success(dunhuangCompanyList(model));
            } else if (addressId == 4) {
                return Result.success(guazhouCompanyList(model));
            } else if (addressId == 5) {
                return Result.success(yumenCompanyList(model));
            } else if (addressId == 6) {
                return Result.success(subeiCompanyList(model));
            } else if (addressId == 7) {
                return Result.success(akesaiCompanyList(model));
            }
        } else {
            int suzhouCount = enterpriseSuzhouMapper.getCompanyCount(model);
            int jintaCount = enterpriseJintaMapper.getCompanyCount(model);
            int dunhuangCount = enterpriseDunhuangMapper.getCompanyCount(model);
            int guazhouCount = enterpriseGuazhouMapper.getCompanyCount(model);
            int yumenCount = enterpriseYumenMapper.getCompanyCount(model);
            int subeiCount = enterpriseSubeiMapper.getCompanyCount(model);
            int akesaiCount = enterpriseAkesaiMapper.getCompanyCount(model);
            int pageCount = suzhouCount / limit;
            int remainderResult = suzhouCount % limit;
            if (pageCount + 1 >= page) {
                vo = suzhouCompanyList(model);
            }
            if (page > pageCount) {
                if (page == pageCount + 1 && remainderResult > 0) {
                    model.setLimit(limit - remainderResult);
                    model.setPage(page - pageCount);
                    vo.getList().addAll(jintaCompanyList(model).getList());
                }
                if (page > pageCount + 1) {
                    model.setLimit(limit);
                    model.setPage((page - (pageCount + 2)) * limit);
                    vo = jintaCompanyList(model);
                }
                int pageCount2 = (suzhouCount + jintaCount) / limit;
                int remainderResult2 = (suzhouCount + jintaCount) % limit;
                if (page > pageCount2) {
                    if (page == pageCount2 + 1 && remainderResult2 > 0) {
                        model.setLimit(limit - remainderResult2);
                        model.setPage(page - pageCount2);
                        vo.getList().addAll(dunhuangCompanyList(model).getList());
                    }
                    if (page > pageCount2 + 1) {
                        model.setLimit(limit);
                        model.setPage((page - (pageCount2 + 2)) * limit);
                        vo = dunhuangCompanyList(model);
                    }
                    int pageCount3 = (suzhouCount + jintaCount + dunhuangCount) / limit;
                    int remainderResult3 = (suzhouCount + jintaCount + dunhuangCount) % limit;
                    if (page > pageCount3) {
                        if (page == pageCount3 + 1 && remainderResult3 > 0) {
                            model.setLimit(limit - remainderResult3);
                            model.setPage(page - pageCount3);
                            vo.getList().addAll(guazhouCompanyList(model).getList());
                        }
                        if (page > pageCount3 + 1) {
                            model.setLimit(limit);
                            model.setPage((page - (pageCount3 + 2)) * limit);
                            vo = guazhouCompanyList(model);
                        }
                        int pageCount4 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount) / limit;
                        int remainderResult4 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount) % limit;
                        if (page > pageCount4) {
                            if (page == pageCount4 + 1 && remainderResult4 > 0) {
                                model.setLimit(limit - remainderResult4);
                                model.setPage(page - pageCount4);
                                vo.getList().addAll(yumenCompanyList(model).getList());
                            }
                            if (page > pageCount4 + 1) {
                                model.setLimit(limit);
                                model.setPage((page - (pageCount4 + 2)) * limit);
                                vo = yumenCompanyList(model);
                            }
                            int pageCount5 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount) / limit;
                            int remainderResult5 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount) % limit;
                            if (page > pageCount5) {
                                if (page == pageCount5 + 1 && remainderResult5 > 0) {
                                    model.setLimit(limit - remainderResult5);
                                    model.setPage(page - pageCount5);
                                    vo.getList().addAll(subeiCompanyList(model).getList());
                                }
                                if (page > pageCount5 + 1) {
                                    model.setLimit(limit);
                                    model.setPage((page - (pageCount5 + 2)) * limit);
                                    vo = subeiCompanyList(model);
                                }
                                int pageCount6 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount + subeiCount) / limit;
                                int remainderResult6 = (suzhouCount + jintaCount + dunhuangCount + guazhouCount + yumenCount + subeiCount) % limit;
                                if (page > pageCount6) {
                                    if (page == pageCount6 + 1 && remainderResult6 > 0) {
                                        model.setLimit(limit - remainderResult6);
                                        model.setPage(page - pageCount6);
                                        vo.getList().addAll(akesaiCompanyList(model).getList());
                                    }
                                    if (page > pageCount6 + 1) {
                                        model.setLimit(limit);
                                        model.setPage((page - (pageCount6 + 2)) * limit);
                                        vo = akesaiCompanyList(model);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            vo.setCount(jintaCount + suzhouCount + dunhuangCount + guazhouCount + yumenCount + subeiCount + akesaiCount);
        }
        return Result.success(vo);
    }

    /**
     * 查询企业详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getComDetails")
    public Result<Object> getComDetails(
            Integer id,
            Integer addressId,
            HttpServletRequest request) {
        String token = request.getHeader("token");
        String userId = TokenUtils.nothingness(token);
        if (userId == null) {
            return Result.error(405, "token不存在");
        }
        AdminUserModel user = adminUserService.getUserById(Integer.parseInt(userId));
        if (user == null) {
            return Result.error(405, "用户不存在");
        }
        if (addressId != null && addressId != 0) {
            if (addressId == 1) {
                return Result.success(suzhoufindModelById(id));
            } else if (addressId == 2) {
                return Result.success(jintafindModelById(id));
            } else if (addressId == 3) {
                return Result.success(dunhuangfindModelById(id));
            } else if (addressId == 4) {
                return Result.success(guazhoufindModelById(id));
            } else if (addressId == 5) {
                return Result.success(yumenfindModelById(id));
            } else if (addressId == 6) {
                return Result.success(subeifindModelById(id));
            } else if (addressId == 7) {
                return Result.success(akesaifindModelById(id));
            }
        }
        return null;
    }

    //肃州区
    public EnterpriseVo suzhouCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseSuzhouMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersSuzhouMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishSuzhouMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(1);
            enterpriseModel.setAddressText("肃州区");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseSuzhouMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel suzhoufindModelById(Integer id) {
        EnterpriseModel model = enterpriseSuzhouMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumSuzhouMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //金塔
    public EnterpriseVo jintaCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseJintaMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersJintaMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishJintaMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(2);
            enterpriseModel.setAddressText("金塔县");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseJintaMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel jintafindModelById(Integer id) {
        EnterpriseModel model = enterpriseJintaMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumJintaMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //敦煌
    public EnterpriseVo dunhuangCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseDunhuangMapper.getCompanyList(model);
        for (int i = 0; i < companyList.size(); i++) {
            companyList.get(i).setHrCount(comRecruitersDunhuangMapper.getCountByComId(companyList.get(i).getId()));
            companyList.get(i).setJobPublishCount(jobPublishDunhuangMapper.getJobPublishCountByComId(companyList.get(i).getId()));
            companyList.get(i).setApplyCount(workApplyDunhuangMapper.getApplyCountByComId(companyList.get(i).getId()));
            if (companyList.get(i).getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (companyList.get(i).getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        companyList.get(i).setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            companyList.get(i).setAddressId(3);
            companyList.get(i).setAddressText("敦煌市");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseDunhuangMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel dunhuangfindModelById(Integer id) {
        EnterpriseModel model = enterpriseDunhuangMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumDunhuangMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //瓜州
    public EnterpriseVo guazhouCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseGuazhouMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersGuazhouMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishGuazhouMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(4);
            enterpriseModel.setAddressText("瓜州县");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseGuazhouMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel guazhoufindModelById(Integer id) {
        EnterpriseModel model = enterpriseGuazhouMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumGuazhouMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //玉门
    public EnterpriseVo yumenCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseYumenMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersYumenMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishYumenMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(5);
            enterpriseModel.setAddressText("玉门市");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseYumenMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel yumenfindModelById(Integer id) {
        EnterpriseModel model = enterpriseYumenMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumYumenMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //肃北
    public EnterpriseVo subeiCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseSubeiMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersSubeiMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishSubeiMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(6);
            enterpriseModel.setAddressText("肃北县");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseSubeiMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel subeifindModelById(Integer id) {
        EnterpriseModel model = enterpriseSubeiMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumSubeiMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    //阿克塞
    public EnterpriseVo akesaiCompanyList(EnterpriseModel model) {
        List<EnterpriseModel> companyList = enterpriseAkesaiMapper.getCompanyList(model);
        for (EnterpriseModel enterpriseModel : companyList) {
            enterpriseModel.setHrCount(comRecruitersAkesaiMapper.getCountByComId(enterpriseModel.getId()));
            enterpriseModel.setJobPublishCount(jobPublishAkesaiMapper.getJobPublishCountByComId(enterpriseModel.getId()));
            if (enterpriseModel.getScaleId() != null) {
                for (int j = 0; j < ScaleTool.SCALE_VO_LIST.size(); j++) {
                    if (enterpriseModel.getScaleId() == ScaleTool.SCALE_VO_LIST.get(j).getId()) {
                        enterpriseModel.setScaleName(ScaleTool.SCALE_VO_LIST.get(j).getData());
                    }
                }
            }
            enterpriseModel.setAddressId(7);
            enterpriseModel.setAddressText("阿克塞县");
        }
        EnterpriseVo vo = new EnterpriseVo();
        int companyCount = enterpriseAkesaiMapper.getCompanyCount(model);
        vo.setList(companyList);
        vo.setCount(companyCount);
        return vo;
    }

    public EnterpriseModel akesaifindModelById(Integer id) {
        EnterpriseModel model = enterpriseAkesaiMapper.selectById(id);
        model.setNatureText(NatureTool.myMap.get(model.getNature()));
        for (ScaleVo vo : ScaleTool.SCALE_VO_LIST) {
            if (model.getScaleId() != null) {
                if (model.getScaleId() == vo.getId()) {
                    model.setScaleName(vo.getData());
                }
            }
        }
        IndustryModel industryModel = industryMapper.getModelByCode(model.getEnterpriseType());
        model.setEnterpriseTypeText(industryModel.getIndustryName());
        List<EnterpriseAlbumModel> enterpriseAlbumModelList = enterpriseAlbumAkesaiMapper.getListByComId(model.getId());
        model.setAlbumModelList(enterpriseAlbumModelList);
        return model;
    }

    /**
     * 查询规模
     */
    @GetMapping("/getScale")
    public Result<Object> getScale(HttpServletRequest request) {

        return Result.success(ScaleTool.SCALE_VO_LIST);
    }

    /**
     * 企业导出
     */
    @PostMapping({"/exportEnterprise"})
    @ResponseBody
    public void exportEnterprise(HttpServletResponse response, @RequestBody EnterpriseModel enterpriseModel) {
        Map<String, Object> map = Maps.newHashMap();
        enterpriseModel.setPage(0);
        enterpriseModel.setLimit(99999);
        if (enterpriseModel.getAddressId() != null && enterpriseModel.getAddressId() != 0) {
            if (enterpriseModel.getAddressId() == 1) {
                EnterpriseVo list = suzhouCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 2) {
                EnterpriseVo list = jintaCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 3) {
                EnterpriseVo list = dunhuangCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 4) {
                EnterpriseVo list = guazhouCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 5) {
                EnterpriseVo list = yumenCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 6) {
                EnterpriseVo list = subeiCompanyList(enterpriseModel);
                map.put("list", list.getList());
            } else if (enterpriseModel.getAddressId() == 7) {
                EnterpriseVo list = akesaiCompanyList(enterpriseModel);
                map.put("list", list.getList());
            }
        } else {
            List<EnterpriseModel> list = new ArrayList<>();
            EnterpriseVo list1 = suzhouCompanyList(enterpriseModel);
            EnterpriseVo list2 = jintaCompanyList(enterpriseModel);
            EnterpriseVo list3 = dunhuangCompanyList(enterpriseModel);
            EnterpriseVo list4 = guazhouCompanyList(enterpriseModel);
            EnterpriseVo list5 = yumenCompanyList(enterpriseModel);
            EnterpriseVo list6 = subeiCompanyList(enterpriseModel);
            EnterpriseVo list7 = akesaiCompanyList(enterpriseModel);
            list.addAll(list1.getList());
            list.addAll(list2.getList());
            list.addAll(list3.getList());
            list.addAll(list4.getList());
            list.addAll(list5.getList());
            list.addAll(list6.getList());
            list.addAll(list7.getList());
            map.put("list", list);
        }
        ClassPathResource classPathResource = new ClassPathResource("C:/jyx/酒泉市管理后台/企业花名册.xlsx");
        String path = classPathResource.getPath();
        TemplateExportParams templateExportParams1 = new TemplateExportParams(path);
        Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
        String fileName = "企业花名册" + time + ".xlsx";
        try {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            response.flushBuffer();
            wb.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 数据统计
     */
    @PostMapping({"/exportDataStatistics"})
    @ResponseBody
    public void exportDataStatistics(HttpServletResponse response, @RequestBody DataVo vo) {
        Map<String, Object> map = Maps.newHashMap();
        List<DataVo> list = statisticsService.getDataCount(vo.getStartTime(),vo.getEndTime());
        map.put("list",list);
        ClassPathResource classPathResource = new ClassPathResource("C:/jyx/酒泉市管理后台/数据统计表.xlsx");
        String path = classPathResource.getPath();
        TemplateExportParams templateExportParams1 = new TemplateExportParams(path);
        Workbook wb = ExcelExportUtil.exportExcel(templateExportParams1, map);
        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy_MM_dd_HH_mm_ss"));
        String fileName = "企业花名册" + time + ".xlsx";
        try {
            response.setContentType("application/vnd.ms-excel");
            response.setHeader("Content-disposition", "attachment;filename=" + fileName);
            response.flushBuffer();
            wb.write(response.getOutputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
